#include "contiki.h"
#include "shell.h"

#include "collect-common.h"
#include "net/netstack.h"
#include "trickle-ipv6.h"

#include <stdio.h>

#define DEBUG 0
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif

/*---------------------------------------------------------------------------*/
PROCESS(shell_ipv6_confnodes_process, "confnodes ipv6");
SHELL_COMMAND(ipv6_confnodes_command,
	      "confnodes",
	      "confnodes[period]: set sample period time in all nodes",
	      &shell_ipv6_confnodes_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_ipv6_confnodes_process, ev, data)
{

    char *line;
    unsigned int aux_data;

    PROCESS_BEGIN();

    line= data;

    while(*line == ' ') {
      line++;
    }
    aux_data = strtoint(line);
    PRINTF("Dato ingresado %u\n", aux_data);
    samplePeriod = aux_data;
    etimer_change_only_interval(&store_timer, CLOCK_SECOND * samplePeriod);
    PRINTF("New samplePeriod received = %u\n", samplePeriod);
    transmissionPeriod = samplePeriod >> 1;
    etimer_change_only_interval(&send_timer_ipv6, CLOCK_SECOND * transmissionPeriod);
    PRINTF("New transmissionPeriod set = %u\n", transmissionPeriod);
    randWaitPeriod = transmissionPeriod;
    PRINTF("New randWaitPeriod set = %u\n", randWaitPeriod);
    trickle_ipv6_send();

    printf("Nuevo Periodo de Muestreo: %u\n", aux_data);

    PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
shell_ipv6_confnodes_init(void)
{
  shell_register_command(&ipv6_confnodes_command);
}
/*---------------------------------------------------------------------------*/
